package models

type Role struct {
	ID   int    `gorm:"primary_key" json:"id"`
	Auth Auth   `json:"user_id"`
	Name string `gorm:"column:role_name" json:"role_name"`
}

func (r *Role) TableName() string {
	return "blog_roles"
}

//查询用户的权限名
func (r *Role) GetRoleNameByUid(uid int) (string, error) {
	var role Role
	err := db.Select("role_name").
		Where("user_id = ?", uid).
		First(&role).Error
	if err != nil {
		return "", err
	}
	return role.Name, nil
}
